package com.df.bpm.utils.businessViewerV2.entityType;

import com.df.bpm.utils.businessViewerV2.Main;
import com.df.bpm.utils.businessViewerV2.res.V_A;
import com.df.common.utils.CommonUtils;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.*;

public class V_entityType extends V_A<M_entityType> {

    @Override
    public List<String> getColNames() {
        return Arrays.asList("ID", "序号", "类型名称");
    }

    @Override
    public List<String> getKeyCols() {
        return Arrays.asList("类型名称");
    }

    @Override
    public Object[] getRowValues(M_entityType row) {
        return new Object[]{row.getEntityTypeIndex(),-1,row.getName()};
    }

    @Override
    public MouseListener mouseAdapter4Table(JTable iTable, List<M_entityType> list) {
        return new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int row = iTable.rowAtPoint(e.getPoint());
                int col = iTable.columnAtPoint(e.getPoint());
                if (row >= 0 ) {
                    if (e.getClickCount() == 2) {// 处理双击事件
//                        System.out.println("Row " + row + "& Col "+col+" double clicked");
                        String typeID=""+iTable.getValueAt(row, 0);
                        if(col==1 && CommonUtils.varIsNotBlank(typeID)){//不为空的双击代表选中
                            selectResult=list.get(row);
                            jd.dispose();//选好窗口消失
                        }else{// 双击空行触发新增 M_entityType
                            if(col==2){
                                C_entityType.editTypeDesc(iTable,row,list);
                                try {
                                    search();
                                } catch (Exception ex) {
                                    throw new RuntimeException(ex);
                                }
                            }
                        }

                    }
                }
            }
        };
    }

    @Override
    public M_entityType getEmptyRow() {
        return new M_entityType();
    }

    @Override
    public void search(List<JTextField> fields)  {
        List<M_entityType> results= C_entityType.search(fields);
        this.putModel(results);
    }

    @Override
    public void hideCol(JTable iTable) {
        Main.hideCol(iTable,0);
    }

    @Override
    public void setDialogSize(int width, int height) {
        jd.setSize(40*unit, 30*unit);
    }

    @Override
    public List<Integer> colWidthSetting() {
        return null;
    }
}
